//
//  RecommendTableViewController.m
//  Travelmemory
//
//  Created by lanou3g on 16/3/23.
//  Copyright © 2016年 ABCD. All rights reserved.
//

#import "RecommendTableViewController.h"
#import "TravelHelper.h"
#import "RecommendModel.h"
#import "SDCycleScrollView.h"
#import "GiFHUD.h"
#import "StoryTableViewCell.h"
#import "PopularTravelCell.h"
#import "RemcommendTableViewCell.h"
#import "StoryCollectionCell.h"
#import "UIImageView+WebCache.h"
#import "NextImageViewController.h"
#import "TravenoteTableViewController.h"
#import "horizontallyModel.h"
#import "SecondCollectionViewCell.h"
#import "MoreViewController.h"
#import "wonderfulTableViewController.h"
#import "PhotoShowViewController.h"
#import "LoginViewController.h"
#import "MJRefresh.h"
#define kScreenWidth self.view.frame.size.width
#define kScreenHeight self.view.frame.size.height

@interface RecommendTableViewController ()<UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, UICollectionViewDelegate, UICollectionViewDataSource,SDCycleScrollViewDelegate>

/** 所有的Model数组 */
/** 每日精选故事 */
@property (nonatomic, strong) NSMutableArray *storyArray;
/** 游记专题 */
@property (nonatomic, strong) NSMutableArray *specialArray;
/** 用于上拉加载使用 */
@property (nonatomic, copy) NSString *next_start;

/** 轮播图 */
@property (nonatomic, strong) SDCycleScrollView *lunBoTuScrollView;
/** 轮播图数数据源 */
@property (nonatomic, strong) NSMutableArray *lunBoTuArray;

@property(nonatomic,strong)NSMutableArray *dataArray;

@end

@implementation RecommendTableViewController

#pragma mark - 懒加载
- (NSMutableArray *)lunBoTuArray {
    if (!_lunBoTuArray) {
        _lunBoTuArray = [NSMutableArray array];
    }
    return _lunBoTuArray;
}

- (void)viewWillDisappear:(BOOL)animated{
    
    self.tabBarController.tabBar.hidden = YES;
}

- (NSMutableArray *)storyArray {
    if (!_storyArray) {
        self.storyArray = [NSMutableArray array];
    }
    return _storyArray;
}
- (NSMutableArray *)specialArray {
    if (!_specialArray) {
        _specialArray = [NSMutableArray array];
    }
    return _specialArray;
}

- (void)viewWillAppear:(BOOL)animated{
    
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    LoginViewController *loginVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"login"];
    [self.parentViewController.tabBarController presentViewController:loginVC animated:YES completion:nil];
    
    // 精选故事cell
    [self.tableView registerClass:[StoryTableViewCell class] forCellReuseIdentifier:@"storycell"];
    //    热门游记
    [self.tableView registerNib:[UINib nibWithNibName:@"PopularTravelCell" bundle:nil] forCellReuseIdentifier:@"hotcell"];
    
    self.navigationItem.title = @"记忆旅行";
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"daohang"] forBarMetrics:UIBarMetricsDefault];
    
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:19]}];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"附近" style:UIBarButtonItemStyleDone target:self action:@selector(rightButtonAction)];
    
    self.dataArray = [NSMutableArray array];
    
    [self handleData];
    [self head];
    [self.tableView addHeaderWithTarget:self action:@selector(headerRereshing)];
    [self.tableView addFooterWithTarget:self action:@selector(footerRereshing)];
    
}

-(void)headerRereshing{

    [[TravelHelper defaultTravelHelper] get:@"http://api.breadtrip.com/v2/index/?lat=40.02930237016372&lng=116.3375773078163&sign=88bd8daa381a99f87acfa8c0c2aaf568" params:nil success:^(id responseObj) {
        
        
        for (NSDictionary *dic in responseObj[@"data"][@"elements"]) {
            //            NSLog(@"%@",dic[@"desc"]);
            if ([dic[@"desc"] isEqualToString:@"广告banner"]) {
                for (NSDictionary *dict in [dic[@"data"] lastObject]) {
                    //                    NSLog(@"%@",dict);
                    
                    RecommendModel *recomendModel = [[RecommendModel alloc] init];
                    [recomendModel setValuesForKeysWithDictionary:dict];
                    [self.lunBoTuArray addObject:recomendModel];
                    //                                        NSLog(@"%@",self.lunBoTuArray);
                }
                
                // 加载轮播图
                [self LunBoTuView];
                
            }else if ([dic[@"desc"] isEqualToString:@""]){
                for (NSDictionary *dict1 in dic[@"data"]) {
                    
                    RecommendModel *recommend = [[RecommendModel alloc] init];
                    
                    if (![dict1.allKeys containsObject:@"title"]) {
                        [recommend setValuesForKeysWithDictionary:dict1];
                        
                        // 用户
                        [recommend setValuesForKeysWithDictionary:dict1[@"user"]];
                        [recommend setValue:dict1[@"user"][@"name"] forKey:@"user_name"];
                        //                        NSLog(@"%@", dict1[@"poi"]);
                        if ([dict1[@"poi"] isKindOfClass:[NSDictionary class]]) {
                            // poi字典
                            [recommend setValue:dict1[@"poi"][@"name"] forKey:@"poi_name"];
                            [recommend setValuesForKeysWithDictionary:dict1[@"poi"]];
                        }
                        [self.storyArray addObject:recommend];
                        //                                                NSLog(@"%@", self.storyArray);
                    }
                    
                }
                
            }else{
                // 精彩热门游记
                for (NSDictionary *dict1 in dic[@"data"]) {
                    RecommendModel *recommend = [[RecommendModel alloc] init];
                    [recommend setValue:dict1[@"id"] forKey:@"ID"];
                    //NSLog(@"----%@", recommend.name);
                    if (![dict1.allKeys containsObject:@"title"]) {
                        [recommend setValuesForKeysWithDictionary:dict1[@"user"]];
                        [recommend setValuesForKeysWithDictionary:dict1];
                        [recommend setValuesForKeysWithDictionary:dic];
                        // 用户字典赋值
                        [recommend setValue:dict1[@"user"][@"name"] forKey:@"user_name"];
                        [self.specialArray addObject:recommend];
                        
                        //                        NSLog(@"%@",self.specialArray);
                    }
                    
                }
            }
            
        }
        [GiFHUD dismiss];
        
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        
        NSLog(@"解析数据失败");
        
    }];
    [self.tableView headerEndRefreshing];
    

}

-(void)footerRereshing{

    [[TravelHelper defaultTravelHelper] get:@"http://api.breadtrip.com/v2/index/?lat=40.02930237016372&lng=116.3375773078163&sign=88bd8daa381a99f87acfa8c0c2aaf568" params:nil success:^(id responseObj) {
        
        
        for (NSDictionary *dic in responseObj[@"data"][@"elements"]) {
            //            NSLog(@"%@",dic[@"desc"]);
            if ([dic[@"desc"] isEqualToString:@"广告banner"]) {
                for (NSDictionary *dict in [dic[@"data"] lastObject]) {
                    //                    NSLog(@"%@",dict);
                    
                    RecommendModel *recomendModel = [[RecommendModel alloc] init];
                    [recomendModel setValuesForKeysWithDictionary:dict];
                    [self.lunBoTuArray addObject:recomendModel];
                    //                                        NSLog(@"%@",self.lunBoTuArray);
                }
                
                // 加载轮播图
                [self LunBoTuView];
                
            }else if ([dic[@"desc"] isEqualToString:@""]){
                for (NSDictionary *dict1 in dic[@"data"]) {
                    
                    RecommendModel *recommend = [[RecommendModel alloc] init];
                    
                    if (![dict1.allKeys containsObject:@"title"]) {
                        [recommend setValuesForKeysWithDictionary:dict1];
                        
                        // 用户
                        [recommend setValuesForKeysWithDictionary:dict1[@"user"]];
                        [recommend setValue:dict1[@"user"][@"name"] forKey:@"user_name"];
                        //                        NSLog(@"%@", dict1[@"poi"]);
                        if ([dict1[@"poi"] isKindOfClass:[NSDictionary class]]) {
                            // poi字典
                            [recommend setValue:dict1[@"poi"][@"name"] forKey:@"poi_name"];
                            [recommend setValuesForKeysWithDictionary:dict1[@"poi"]];
                        }
                        [self.storyArray addObject:recommend];
                        //                                                NSLog(@"%@", self.storyArray);
                    }
                    
                }
                
            }else{
                // 精彩热门游记
                for (NSDictionary *dict1 in dic[@"data"]) {
                    RecommendModel *recommend = [[RecommendModel alloc] init];
                    [recommend setValue:dict1[@"id"] forKey:@"ID"];
                    //NSLog(@"----%@", recommend.name);
                    if (![dict1.allKeys containsObject:@"title"]) {
                        [recommend setValuesForKeysWithDictionary:dict1[@"user"]];
                        [recommend setValuesForKeysWithDictionary:dict1];
                        [recommend setValuesForKeysWithDictionary:dic];
                        // 用户字典赋值
                        [recommend setValue:dict1[@"user"][@"name"] forKey:@"user_name"];
                        [self.specialArray addObject:recommend];
                        
                        //                        NSLog(@"%@",self.specialArray);
                    }
                    
                }
            }
            
        }
        [GiFHUD dismiss];
        
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        
        NSLog(@"解析数据失败");
        
    }];


}
-(void)rightButtonAction{
    
    if ([self.navigationItem.rightBarButtonItem.title isEqualToString:@"附近"]) {
        PhotoShowViewController *nearVC = [[PhotoShowViewController alloc] init];
        //nearVC.tabBarController.tabBar.hidden = YES;
        [self showViewController:nearVC sender:nil];
        
    }
    
    
    
}

-(void)handleData{
    
    //  初始化
    self.lunBoTuArray = [NSMutableArray array];
    self.storyArray = [NSMutableArray array];
    self.specialArray = [NSMutableArray array];
    
    [[TravelHelper defaultTravelHelper] get:@"http://api.breadtrip.com/v2/index/?lat=40.02930237016372&lng=116.3375773078163&sign=88bd8daa381a99f87acfa8c0c2aaf568" params:nil success:^(id responseObj) {
        
        
        for (NSDictionary *dic in responseObj[@"data"][@"elements"]) {
            //            NSLog(@"%@",dic[@"desc"]);
            if ([dic[@"desc"] isEqualToString:@"广告banner"]) {
                for (NSDictionary *dict in [dic[@"data"] lastObject]) {
                    //                    NSLog(@"%@",dict);
                    
                    RecommendModel *recomendModel = [[RecommendModel alloc] init];
                    [recomendModel setValuesForKeysWithDictionary:dict];
                    [self.lunBoTuArray addObject:recomendModel];
                    //                                        NSLog(@"%@",self.lunBoTuArray);
                }
                
                // 加载轮播图
                [self LunBoTuView];
                
            }else if ([dic[@"desc"] isEqualToString:@""]){
                for (NSDictionary *dict1 in dic[@"data"]) {
                    
                    RecommendModel *recommend = [[RecommendModel alloc] init];
                    
                    if (![dict1.allKeys containsObject:@"title"]) {
                        [recommend setValuesForKeysWithDictionary:dict1];
                        
                        // 用户
                        [recommend setValuesForKeysWithDictionary:dict1[@"user"]];
                        [recommend setValue:dict1[@"user"][@"name"] forKey:@"user_name"];
                        //                        NSLog(@"%@", dict1[@"poi"]);
                        if ([dict1[@"poi"] isKindOfClass:[NSDictionary class]]) {
                            // poi字典
                            [recommend setValue:dict1[@"poi"][@"name"] forKey:@"poi_name"];
                            [recommend setValuesForKeysWithDictionary:dict1[@"poi"]];
                        }
                        [self.storyArray addObject:recommend];
                        //                                                NSLog(@"%@", self.storyArray);
                    }
                    
                }
                
            }else{
                // 精彩热门游记
                for (NSDictionary *dict1 in dic[@"data"]) {
                    RecommendModel *recommend = [[RecommendModel alloc] init];
                    [recommend setValue:dict1[@"id"] forKey:@"ID"];
                    //NSLog(@"----%@", recommend.name);
                    if (![dict1.allKeys containsObject:@"title"]) {
                        [recommend setValuesForKeysWithDictionary:dict1[@"user"]];
                        [recommend setValuesForKeysWithDictionary:dict1];
                        [recommend setValuesForKeysWithDictionary:dic];
                        // 用户字典赋值
                        [recommend setValue:dict1[@"user"][@"name"] forKey:@"user_name"];
                        [self.specialArray addObject:recommend];
                        
                        //                        NSLog(@"%@",self.specialArray);
                    }
                    
                }
            }
            
        }
        [GiFHUD dismiss];
        
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        
        NSLog(@"解析数据失败");
        
    }];
    
}

-(void)LunBoTuView{
    
    // 图片数组
    NSMutableArray *imageArray = [NSMutableArray array];
    for (int i = 0; i < self.lunBoTuArray.count; i++) {
        RecommendModel *model = self.lunBoTuArray[i];
        [imageArray addObject:model.image_url];
    }
    self.lunBoTuScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200) imageURLStringsGroup:imageArray];
    // 间隔时间
    self.lunBoTuScrollView.autoScrollTimeInterval = 3.0;
    self.lunBoTuScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    self.lunBoTuScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
    
    self.lunBoTuScrollView.dotColor = [UIColor orangeColor];
    self.tableView.tableHeaderView = self.lunBoTuScrollView;
    
    self.lunBoTuScrollView.delegate = self;
    
}
// 轮播图点击事件
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    RecommendModel *model = self.lunBoTuArray[index];
    
    NextImageViewController *nextVC = [[NextImageViewController alloc]init];
    nextVC.model = model;
    [self.navigationController pushViewController:nextVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0) {
        return 1;
    }
    
    return self.specialArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    if (indexPath.section == 0) {
        
        StoryTableViewCell *stroycell = [tableView dequeueReusableCellWithIdentifier:@"storycell" forIndexPath:indexPath];
        stroycell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return stroycell;
    }else{
        
        RecommendModel *model = self.specialArray[indexPath.row];
        /** 区分Cell的标记 */
        if ([model.type integerValue]== 4 || [model.type integerValue]== 12){
            PopularTravelCell *hotcell = [tableView dequeueReusableCellWithIdentifier:@"hotcell"];
            hotcell.titleLabel.text = model.name;
            hotcell.titleLabel.font = [UIFont boldSystemFontOfSize:20.0f];
            hotcell.selectionStyle = UITableViewCellSelectionStyleNone;
            //            背景设置圆角
            hotcell.HotImageView.layer.masksToBounds = YES;
            hotcell.HotImageView.layer.cornerRadius = hotcell.HotImageView.frame.size.width / 28;
            //             背景图片
            [hotcell.HotImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_image] placeholderImage:[UIImage imageNamed:@"5-1.png"] options:SDWebImageCacheMemoryOnly completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                
            }];
            //            浏览次数
            hotcell.timeLabel.text = [NSString stringWithFormat:@"%@ %@ %@次浏览", model.first_day, model.day_count, model.view_count];
            hotcell.addressLabel.text = model.popular_place_str;
            
            //            热门人物头像设置圆角
            hotcell.iconImageView.layer.masksToBounds = YES;
            hotcell.iconImageView.layer.cornerRadius = hotcell.iconImageView.frame.size.width / 2;
            //            热门人物头像
            [hotcell.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar_l] placeholderImage:[UIImage imageNamed:@""] options:SDWebImageCacheMemoryOnly completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                
            }];
            //            人物名字
            hotcell.nameLabel.text = model.user_name;
            return hotcell;
        }
        
        
    }
    
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // 精选故事
    RecommendModel *model = self.specialArray[indexPath.row];
    if ([model.type integerValue]== 4) {
        TravenoteTableViewController *travelVC = [[TravenoteTableViewController alloc] init];
        travelVC.recommendModel = model;
        [self.navigationController pushViewController:travelVC animated:YES];
        
        
    }
    //    // 专题
    //    if ([model.type integerValue] == 5) {
    //        NextImageViewController *nextVC = [[NextImageViewController alloc] init];
    //        nextVC.model = model;
    //        [self.navigationController pushViewController:nextVC animated:YES];
    //    }
    
}

//  行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 200;
    }
    return self.view.frame.size.height * 0.3;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(10, 5, 5, CGRectGetHeight(view.frame) - 10)];
    view1.backgroundColor = [UIColor colorWithRed:0.386 green:0.911 blue:0.957 alpha:1];
    [view addSubview:view1];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, kScreenWidth * 1.5, CGRectGetHeight(view.frame))];
    [view addSubview:label];
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth - 50, 0, 50, CGRectGetHeight(view.frame))];
    //    [button setBackgroundImage:[UIImage imageNamed:@"iconfont-i"] forState:UIControlStateNormal];
    [button setTitle:@"更多" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    //    button.backgroundColor = [UIColor orangeColor];
    [button setTitleColor:[UIColor colorWithRed:0.707 green:0.694 blue:0.695 alpha:1.0] forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    view.backgroundColor = [UIColor whiteColor];
    if (section == 0) {
        label.text = @"留得住的回忆";
        
        //        label.font = [UIFont boldSystemFontOfSize:15.0f];
        return view;
    }
    else {
        //        [button removeFromSuperview];
        label.text = @"精彩游记和专题";
        return view;
    }
    
}

-(void)buttonAction{
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 30;
}

#pragma mark - collectionViewCell的注册
- (void)tableView:(UITableView *)tableView willDisplayCell:(StoryTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        // 注册
        [cell.collectionView registerNib:[UINib nibWithNibName:@"StoryCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"cell"];
        cell.collectionView.delegate = self;
        cell.collectionView.dataSource = self;
        cell.backgroundColor = [UIColor grayColor];
        // 刷新数据
        [cell.collectionView reloadData];
    }
    
}

#pragma mark - 精彩故事分区数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    //    if (section == 0) {
    //        return self.storyArray.count;
    //    }
    
    return self.dataArray.count - 2;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    if (indexPath.item == 0) {
        
        // Register nib file for the cell
        UINib *nib = [UINib nibWithNibName:@"StoryCollectionCell"
                                    bundle: [NSBundle mainBundle]];
        [collectionView registerNib:nib forCellWithReuseIdentifier:@"cell"];
        StoryCollectionCell *cell = [[StoryCollectionCell alloc]init];
        
        // Set up the reuse identifier
        cell = [collectionView dequeueReusableCellWithReuseIdentifier: @"cell"
                                                         forIndexPath:indexPath];
        RecommendModel *model = self.storyArray[indexPath.row];
        
        [cell.HeaderImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_image_s] placeholderImage:[UIImage imageNamed:@"5-1.png"] options:SDWebImageCacheMemoryOnly completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            
        }];
        
        cell.ContentLabel.text = [NSString stringWithFormat:@"%@", model.text];
        
        [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar_l] placeholderImage:[UIImage imageNamed:@"5-1.png"] options:SDWebImageCacheMemoryOnly completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            
        }];
        // NSLog(@"%@",model.avatar_l);
        cell.NameLabel.text= model.user_name;
        if (model.poi_name != NULL) {
            cell.addressLabel.text = [NSString stringWithFormat:@"%@ %@", model.poi_name, model.address];
        }else {
            cell.addressLabel.text = @"";
        }
        return cell;
        
        
    }else{
        
        // Register nib file for the cell
        UINib *nib = [UINib nibWithNibName:@"SecondCollectionViewCell"
                                    bundle: [NSBundle mainBundle]];
        [collectionView registerNib:nib forCellWithReuseIdentifier:@"celled"];
        SecondCollectionViewCell *celled = [[SecondCollectionViewCell alloc]init];
        
        // Set up the reuse identifier
        celled = [collectionView dequeueReusableCellWithReuseIdentifier: @"celled"
                                                           forIndexPath:indexPath];
        
        
        
        horizontallyModel *model = self.dataArray[indexPath.row];
        
        [celled.headImage sd_setImageWithURL:[NSURL URLWithString:model.cover_url] placeholderImage:[UIImage imageNamed:@"5-1.png"] options:SDWebImageCacheMemoryOnly completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            
        }];
        
        
        celled.statementsLabel.text = [NSString stringWithFormat:@"%@", model.content];
        celled.nameText.text = [NSString stringWithFormat:@"%@",model.title];
        
        return celled;
    }
    
    
    return nil;
}

-(void)head{
    
    [[TravelHelper defaultTravelHelper] get:@"http://nahaowan.com/api/v1/collection/list?location=%E5%8C%97%E4%BA%AC&pagesize=10&list=explore&" params:nil success:^(id responseObj) {
        
        
        for (NSDictionary *dict in responseObj[@"data"][@"list"]) {
            
            
            horizontallyModel *horizontal = [[horizontallyModel alloc] init];
            
            [horizontal setValuesForKeysWithDictionary:dict];
            
            
            
            [self.dataArray addObject:horizontal];
            
        }
        
        
    } failure:^(NSError *error) {
        
        
    }];
    
    
    
    
}

#pragma mark - collectionCell点击事件
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    //NSLog(@"%zd", indexPath.row);
    
    if (indexPath.item == 0) {
        
        MoreViewController *nextVC = [[MoreViewController alloc] init];
        self.tabBarController.tabBar.hidden = YES;
        [self showViewController:nextVC sender:nil];
        
        
    }else{
        
        horizontallyModel *model = self.dataArray[indexPath.row];
        
        wonderfulTableViewController *wonderfulVC = [[wonderfulTableViewController alloc] init];
        
        wonderfulVC.model = model;
        
        self.tabBarController.tabBar.hidden = YES;
        
        [self showViewController:wonderfulVC sender:nil];
        
        
        ;
        if (indexPath.item == 1) {
            
            wonderfulVC.nameId =@"441";
            
        }else if (indexPath.item == 2){
            
            wonderfulVC.nameId = @"426";
            
        }else if (indexPath.item == 3){
            
            wonderfulVC.nameId =@"435";
            
        }else if (indexPath.item == 4){
            
            wonderfulVC.nameId = @"379";
            
        }else if (indexPath.item == 5){
            
            wonderfulVC.nameId = @"438";
            
        }else if (indexPath.item == 6){
            
            wonderfulVC.nameId = @"428";
        }else if (indexPath.item == 7){
            
            wonderfulVC.nameId = @"437";
            
        }
    }
    
    
}



/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
 } else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
